import { Service } from "cl-admin";
import BaseService from "@/service/base";
import dayjs from "dayjs";


@Service("cluecus")
class Cluecus extends BaseService {
	// 已派单列表
	singleList({ size, bra_id = [], ...args }) {
		let params = {
			...args,
			page_size: size,
			bra_id: bra_id.join()
		};
		return this.$get("/hlists", { params }).then(res => {
			let nowDate = dayjs();
			return {
				list: res.list.map(v => {
					let status = v.status;
					let startDate = dayjs(v.start_time);
					if (v.real_amount != undefined && Number(v.real_amount) > 0) {
						status = 9;
					}
					if (status == 1 && startDate.isBefore(nowDate, 'minute')) {
						status = 10;
					}
					return {
						...v,
						region: [v.province, v.city, v.area],
						rel_place: [v.new_province, v.new_city, v.new_area].join("/"),
						status,
						is_appoint_biz: !!v.appointed_biz_id,
						wait_service_items: JSON.parse(
							(v.wait_service_items || "[]").replace(/(&quot;)/g, '"')
						)
					};
				}),
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 获取单条详情
	singleDetail(id) {
		return this.$get("/single", { params: { id } });
	}
	// 重新派出
	translate(params) {
		return this.$post("/translate", params);
	}
	// 流失或退订
	action(params) {
		return this.$post("/action", params);
	}

	//新增派单
	add(params) {
		return this.$post("/add", params);
	}

	// 客户线索退回审核--已对
	audit(params) {
		return this.$post("/audit", params);
	}

	// 接单汇总列表
	cluereport({ time, ...args }) {
		let params = { ...args };
		if (time && time.length) {
			params.startTime = time[0];
			params.endTime = time[1];
		}
		return this.$get("/cluereport", { params });
	}

	// 派单汇总详细
	cluereportDetail({ time, size, ...args }) {
		let params = {
			...args,
			size,
			pagesize: size,
			btime: time?.[0] || '',
			etime: time?.[1] || ''
		};
		return this.$get("/cluereportDetail", { params }).then(res => this.pagination(params, res));
	}
}
export default Cluecus;
